function outbreakSqlCreateInfoTable()
	if !sql.TableExists("player_info") then
		sql.Query("CREATE TABLE player_info ( unique_id varchar(255), money int )")
		if(sql.TableExists("player_info") == true) then
			print("Created table player_info!")
			return true
		else
			print("Failed to create table player_info!")
			print(sql.LastError(result))
		end
	end
	
	return false
end

function outbreakSqlCreateSkillsTable()
	if !sql.TableExists("player_skills") then
		sql.Query("CREATE TABLE player_skills ( unique_id varchar(255), stamina int, strength int, hp int )")
		if(sql.TableExists("player_skills") == true) then
			print("Created table player_skills!")
			return true
		else
			print("Failed to create table player_skills!")
			print(sql.LastError(result))
		end
	end
	
	return false
end

function outbreakSqlValidateInfoTable()
	if !sql.TableExists("player_info") then
		return false
	end
	
	query = "PRAGMA table_info(player_info);"
	pragmaResult = sql.Query(query)
	for key, value in pairs(pragmaResult) do
		if value['name'] != "unique_id" and value['name'] != "money" then
			return false
		end
	end
	
	return true
end

function outbreakSqlValidateSkillsTable()
	if !sql.TableExists("player_skills") then
		return false
	end
	
	query = "PRAGMA table_info(player_skills);"
	pragmaResult = sql.Query(query)
	for key, value in pairs(pragmaResult) do
		if value['name'] != "unique_id" and value['name'] != "stamina" and value['name'] != "strength" and value['name'] != "hp" then
			return false
		end
	end
	
	return true
end
 
function outbreakSqlCreatePlayer( ply )
	result = sql.Query( "INSERT INTO player_info (`unique_id`, `money`) VALUES ('"..ply:SteamID().."', '100')" )
	if result then
		result = sql.Query( "INSERT INTO player_skills (`unique_id`, `stamina`, `strength`, `hp`) VALUES ('"..ply:SteamID().."', '1', '1', '1')" )
		if result then
			print("Player account created !\n")
			return outbreakSqlSelectPlayer(ply)
		else
			result = sql.Query( "DELETE * FROM player_info WHERE unique_id = '"..ply:SteamID().."'" )			
			print("Something went wrong with creating a players skills !\n")
		end
	else
		print("Something went wrong with creating a players info !\n")
	end
	
	return false
end

function outbreakSqlSelectPlayer( ply )
	data = sql.Query("SELECT * FROM player_info INNER JOIN player_skills ON player_info.unique_id=player_skills.unique_id WHERE unique_id = '"..ply:SteamID().."'")
	
	if data then
		PrintTable(data)
		return data
	end
	
	return false
end
 
function outbreakSqlUpdatePlayer( ply, data )
	result_info = sql.Query("UPDATE player_info SET money = "..data['money'].." WHERE unique_id = '"..ply:SteamID().."'")
	result_skills = sql.Query("UPDATE player_skills SET stamina = "..data['stamina']..", strength = "..data['strength']..", hp = "..data['hp'].." WHERE unique_id = '"..ply:SteamID().."'")
	print("UPDATE player_info SET money = "..data['money'].." WHERE unique_id = '"..ply:SteamID().."'")
	print("UPDATE player_skills SET stamina = "..data['stamina']..", strength = "..data['strength']..", hp = "..data['hp'].." WHERE unique_id = '"..ply:SteamID().."'")
	
	if !result_info then
		print("Error updating player_info!")
	end
	if !result_skills then
		print("Error updating player_skills!")
	end
	
	--ply:ChatPrint("Stats updated!, set strength to " .. strength .. "in savestat")
end